package controllers;

import play.*;
import play.mvc.*;
import play.mvc.Http.*;

import models.*;

public class Secured extends Security.Authenticator {

    @Override
    public String getUsername(Context ctx) {
		String uuid = ctx.session().get("uuid");
		String loggedUser = LogSession.getUsernameFromUUID(uuid);

        return loggedUser;
    }

    @Override
    public Result onUnauthorized(Context ctx) {
		ctx.flash().put("refuri",ctx.request().uri());		
		
		String lang = ctx.request().getQueryString("lang");
		if (lang == null)
			lang = "en";
		
        return redirect(routes.Application.login(lang));
    }
}